package com.pjh.whonumber;

import android.content.Context;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallingController extends android.telephony.PhoneStateListener
{
	private Context _context;
	private int callFalg = 0;


	public CallingController(Context $context)
	{
		super();
		_context = $context;
	}


	@Override
	public void onCallStateChanged(int state, String incomingNumber)
	{
		switch (state) {
		case TelephonyManager.CALL_STATE_IDLE:
			Log.i("pjh",
					"MyPhoneStateListener->onCallStateChanged() -> CALL_STATE_IDLE "
							+ incomingNumber);
			break;
		case TelephonyManager.CALL_STATE_OFFHOOK:
			Log.i("pjh",
					"MyPhoneStateListener->onCallStateChanged() -> CALL_STATE_OFFHOOK "
							+ incomingNumber);
			break;
		case TelephonyManager.CALL_STATE_RINGING:
			Log.i("pjh",
					"MyPhoneStateListener->onCallStateChanged() -> CALL_STATE_RINGING "
							+ incomingNumber);
			break;
		default:
			Log.i("pjh",
					"MyPhoneStateListener->onCallStateChanged() -> default -> "
							+ Integer.toString(state));
			break;
		}
	}
	@Override
	public void onServiceStateChanged(ServiceState serviceState) {
		switch (serviceState.getState()) {
		case ServiceState.STATE_IN_SERVICE:
			Log.i("pjh",
					"MyPhoneStateListener->onServiceStateChanged() -> STATE_IN_SERVICE");
			serviceState.setState(ServiceState.STATE_IN_SERVICE);
			break;
		case ServiceState.STATE_OUT_OF_SERVICE:
			Log.i("pjh",
					"MyPhoneStateListener->onServiceStateChanged() -> STATE_OUT_OF_SERVICE");
			serviceState.setState(ServiceState.STATE_OUT_OF_SERVICE);
			break;
		case ServiceState.STATE_EMERGENCY_ONLY:
			Log.i("pjh",
					"MyPhoneStateListener->onServiceStateChanged() -> STATE_EMERGENCY_ONLY");
			serviceState.setState(ServiceState.STATE_EMERGENCY_ONLY);
			break;
		case ServiceState.STATE_POWER_OFF:
			Log.i("pjh",
					"MyPhoneStateListener->onServiceStateChanged() -> STATE_POWER_OFF");
			serviceState.setState(ServiceState.STATE_POWER_OFF);
			break;
		default:
			Log.i("pjh",
					"MyPhoneStateListener->onServiceStateChanged() -> default -> "
							+ Integer.toString(serviceState.getState()));
			break;
		}
	}


	//    public void call()
	//    {
	//        if (callFalg == 1)
	//        {
	//            try
	//            {
	//                Intent new_intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	//                new_intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
	//                _context.sendOrderedBroadcast(new_intent, null);
	//                new_intent = null;
	//            } catch (Exception e)
	//            {
	//                e.printStackTrace();
	//            }
	//             
	//            try
	//            {
	//                Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
	//                buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
	//                _context.sendOrderedBroadcast(buttonUp, null);
	//                buttonUp = null;
	//            } catch (Exception e)
	//            {
	//                e.printStackTrace();
	//            }
	//        }
	//    }
	//     
	//    private class interruptCall extends Thread
	//    {
	//        public void run()
	//        {
	//            try
	//            {
	////              sleep(3000);
	//            } catch (Exception c)
	//            {
	//                c.printStackTrace();
	//            }
	//             
	//        }
	//    }
}